<?php
require_once dirname(__FILE__).'/JsonRpcRequest.class.php';

if (isset($GLOBALS ['argc']) && $GLOBALS ['argc'] > 0) {
	$cmd = array ();
	$argv = $GLOBALS ['argv'];
	for($i = 1; $i < $GLOBALS ['argc']; $i ++) {
		list ( $key, $val ) = explode ( '=', $argv [$i], 2 );
				$cmd [$key] = $val;
	}

} else	$cmd=$_REQUEST;
$app=array();
reset($cmd);
for($i=Count($cmd)-1;$i>=0;$i--){
	list($key,$val)=each($cmd);
	if(strncasecmp($key,'app_',4)===0){
		unset($cmd[$key]);
		$akey=substr($key,4,strlen($key)-4);
		$akey= preg_replace('/[^a-z0-9_]+/i', '',$akey);
		$app[$akey]=$val;
	}
}
reset($cmd);	
if(! isset($app['url'])){
$str=<<<EOF
<pre>
	app_url=[json rpc url地址,必须] 
	app_act=[json rpc action,必须] 
	app_key=[json rpc key,必须] 
	app_secret=[json rpc secret,必须]  
	app_info=[是否打印结果,可选，默认为0,不打印]  
	app_lang=[json rpc 语言,可选(en,zh_cn),默认为服务器默认设置]
</pre>
EOF;
	echo $str;
	exit;
}
$request=new JsonRpcRequest($app['url'],$app['key'],$app['secret']);
if($app['lang']) $request->lang=$app['lang'];
$result=$request->get($app['act'],$cmd,false);

$errno=0;$errmsg='';
if($result===false){
	echo 'json rpc error['.$request->err_no.'],'.$request->err_msg;
	echo "\n".$app['act'].' fail !!';
	exit;
}else if(isset($app['info']) && $app['info']==1){
  echo "<pre>\n";
  print_r($result);
  echo "</pre>\n";
}
echo $app['act'].' success';